package com.example.origin.spider.service;

import com.example.origin.spider.webmagic.HttpClientProcessor;
import org.springframework.stereotype.Service;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

import java.util.Map;

@Service("infolink-group")
public final class InfoLinkGroupProcessor extends HttpClientProcessor {

    @Override
    public void process(ResultItems resultItems, Task task) {
        System.out.println("get page: " + resultItems.getRequest().getUrl());
        for (Map.Entry<String, Object> entry : resultItems.getAll().entrySet()) {
            System.out.println(entry.getKey() + ":\t" + entry.getValue());
        }
    }

    @Override
    public void process(Page page) {
        System.out.println("=======================>>"+page.getUrl());
//        if (page.getUrl().get().contains("ip.chaxunjiao.com")){
//            page.putField("ip", page.getHtml().css("h3").get());
//            return;
//        }else {
//            //解折返回的数据page,并目把解折的结果放到ResultItems中
//            page.putField("div", page.getHtml().css("div.dt a").all());
//        }
//
//        page.addTargetRequest("https://ip.chaxunjiao.com/");
    }
}
